package wj.tree;

import wj.WJValue;

public class WhileNode implements WJNode {

	private WJNode conditionNode;
	private WJNode blockNode;
	
	public WhileNode(WJNode conditionNode, WJNode blockNode){
		this.conditionNode = conditionNode;
		this.blockNode = blockNode;
	}
	
	@Override
	public WJValue evaluate() {
		
		while(conditionNode.evaluate().toBoolean()){
			WJValue returnVal = blockNode.evaluate();

			if(!returnVal.equals(WJValue.NULL))
				return returnVal;
		}
		
		return WJValue.NULL;
	}

}
